import React, { Component, createRef, forwardRef, useImperativeHandle, useRef } from 'react'

export default class App extends Component {
  child = createRef()
  render() {
    return (
      <div>
        <button onClick={()=>{this.child.current.say()}}>控制台</button>
        <h1>函数引用forwardRef和usrRef实现ref</h1>
        <Child ref={this.child}/>
      </div>
    )
  }
}



const Child =forwardRef(function(porps,ref){
  const input = useRef()
   function say(){
    console.log("可以运行");
  }
  useImperativeHandle(ref,()=>{
    return {say}
  })
  return <>
    <input ref={input}></input>
    <button onClick={()=>{input.current.value= "点击"}}>点击</button>
  </>
}) 


